// import axios from 'axios'

const login = async (params) => {
    let formData = new FormData();
    formData.append('username', params.username);
    formData.append('password', params.password);
    return await new Promise((resolve, reject) => {
        axios.post('/sys/login/loginChooseProjectByUserName', formData).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
        formData = null;
    })
}

const getLoginerProjectList = async () => {
    return await new Promise((resolve, reject) => {
        axios.get('/sys/login/getProjectList', {}).then(res => {
            resolve(res.data.data)
        }).catch(err => {
            reject(err)
        })
    })
}

const choiceProject = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.post('/index/login/setBelong', params).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

const getLoginInfo = async () => {
    return await new Promise((resolve, reject) => {
        axios.get('/index/index/getLoginInfo').then(res => {
            resolve(res.data.data)
        }).catch(err => {
            reject(err)
        })
    })
}

const getMenu = async () => {
    return await new Promise((resolve, reject) => {
        axios.get('/index/menu/getMenu', {}).then(res => {
            resolve(res.data.data)
        }).catch(err => {
            reject(err)
        })
    })
}

const userExit = async () => {
    return await new Promise((resolve, reject) => {
        axios.get('/sys/login/userExit').then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

const openIdLogin = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.get('/sys/login/loginChooseProjectByOpenId', {params}).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        });
    });
}

const unionIdLogin = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.get('/sys/login/loginByUnionID?UnionID=' + params.UnionId).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        });
    });
}

export default {
    login,
    getLoginerProjectList,
    choiceProject,
    getLoginInfo,
    getMenu,
    userExit,
    openIdLogin,
    unionIdLogin
}